#define _CRT_SECURE_NO_WARNINGS   1

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int k;
	int *a;
	cin >> n >> k;
	a = new int[n];
	for (int i = 0; i<n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	int left = 0;
	int right = 0;
	int max = 0;
	int sub = 0;
	while (right<n)
	{
		sub = a[right] - a[left];
		while (sub>k)
		{
			left++;
			break;
		}
		if (max<right - left + 1 || max == 0)
		{
			max = right - left + 1;
		}
		right++;
	}
	cout << max << endl;
	return 0;
}